package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.HomestayMapper;
import org.rcloud.io.model.Homestay;
import org.rcloud.io.service.HomestayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/3/12.
 */
@Service(value="HomestayService")
public class HomestayServiceImpl implements HomestayService{
    @Autowired
    private HomestayMapper homestayMapper;

    @Override
    public PageVo<Homestay> findHomestay() {
        try {
            List<Homestay> list = homestayMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo findByEid(String eid) {

        try {
            Homestay homestay = homestayMapper.selectByEid(eid);
            return ResultVo.setOK(homestay);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo saveHomestay(Homestay homestay) {

        try {
            int i = homestayMapper.insertSelective(homestay);
            return ResultVo.setOK(i);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo findById(int id) {

        try {
            Homestay homestay = homestayMapper.selectByPrimaryKey(id);
            return ResultVo.setOK(homestay);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updateHomestay(Homestay homestay) {

        try {
            int i = homestayMapper.updateByPrimaryKeySelective(homestay);
            return ResultVo.setOK(i);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public ResultVo updateArtid(String nameTitle, String INF01) {

        try {
            int i = homestayMapper.updateByTitle(nameTitle,INF01);
            return ResultVo.setOK(i);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }
}
